<template>
    <div style="padding: 10px;">
        <el-form :model="formData" ref="queryForm" class="queryForm" :inline="true" :rules="Rules" label-width="auto"
                 @submit.native.prevent>
            <!--  <el-form-item label="" desc="" prop="bpmId">
                  <el-input v-model.trim="formData.bpmId" placeholder="" clearable size="small" style="width:120px;" />
              </el-form-item>-->
            <!--      <el-form-item label="对应生产计划单id" desc="对应生产计划单id" prop="lineId">
                      <el-input v-model.trim="formData.lineId" placeholder="对应生产计划单id" clearable size="small"
                                style="width:120px;" />
                  </el-form-item>-->
            <!--    <el-form-item label="对应表单Id" desc="对应表单Id" prop="formId">
                    <el-input v-model.trim="formData.formId" placeholder="对应表单Id" clearable size="small"
                              style="width:120px;" />
                </el-form-item>-->
            <el-form-item label="表单字段" desc="表单字段" prop="formId">
                <!--下拉表单-->
                <el-select v-model="formData.formId"
                           clearable
                           @change="valueid=>{
                             changeFormId(valueid)
                            }"
                >
                    <el-option
                            v-for="formFeild in formFieldList"
                            :value="formFeild.id"
                            :label="formFeild.fieldName"
                            :key="formFeild.id"
                    ></el-option>
                </el-select>
            
            </el-form-item>
            <!-- 联动 下拉   -->
            <el-form-item label="表达式" desc="表达式" prop="expression">
                <el-select v-model="formData.expression"
                           clearable
                >
                    <el-option
                            v-for="expressone in mesBpmConditionExpressionList"
                            :value="expressone.expression"
                            :label="expressone.expression"
                            :key="expressone.expression"
                    ></el-option>
                </el-select>
            
            
            </el-form-item>
            
            
            <el-form-item label="对应字段值" desc="对应字段值" prop="fieldValue">
                <el-input v-model.trim="formData.fieldValue" placeholder="对应字段值" clearable size="small"
                          style="width:120px;" />
            </el-form-item>
            <!--  <el-form-item label="对应字段类型" desc="对应字段类型 1文本  2单选框  3多选框  4下拉框 5、数字" prop="fieldType">
                  <dic-select v-model="formData.fieldType" :code="dicInner.mes_bpm_condition_fieldType"
                              placeholder="对应字段类型 1文本  2单选框  3多选框  4下拉框 5、数字" clearable size="small"
                              style="width:120px;" />
              </el-form-item>-->
            
            <!--   <el-form-item label="预计用时(天)" desc="预计用时(天)" prop="orderNum">
                   <el-input v-model.trim="formData.orderNum" placeholder="预计用时(天)" clearable size="small"
                             style="width:120px;" />
               </el-form-item>-->
            <!--   <el-form-item label="状态" desc="状态 1 正常  5暂停 10废除" prop="state">
                   <dic-select v-model="formData.state" :code="dicInner.mes_bpm_condition_state"
                               placeholder="状态 1 正常  5暂停 10废除" clearable size="small" style="width:120px;" />
               </el-form-item>-->
        </el-form>
    </div>
</template>
<script>
  import { getUrlParam } from '@/utils/index';
  import { alertWithPaylod } from '@/utils/alertUtil';
  import * as  api from '@/apis/mesBpmCondition.api.js';
  import { default as FormDialog } from '@codegenarate/mydialogplus';
  import { fillData, validatePromise } from '@/utils/index';
  
  const Rules = {
    'id': [{ required: false, message: '主键ID', trigger: 'blur' }],
    'bpmId': [{ required: false, message: '', trigger: 'blur' }],
    'lineId': [{ required: false, message: '对应生产计划单id', trigger: 'blur' }],
    'formId': [{ required: true, message: '对应表单Id', trigger: 'blur' }],
    'fieldName': [{ required: false, message: '对应产品id', trigger: 'blur' }],
    'fieldValue': [{ required: false, message: '对应字段值', trigger: 'blur' }],
    'fieldType': [{ required: false, message: '对应字段类型', trigger: 'blur' }],
    'expression': [{ required: true, message: '表达式', trigger: 'blur' }],
    'orderNum': [{ required: false, message: '预计用时(天)', trigger: 'blur' }],
    'state': [{ required: false, message: '状态', trigger: 'blur' }],
    'remarks': [{ required: false, message: '备注', trigger: 'blur' }],
    'tenantType': [{ required: false, message: '租户类型', trigger: 'blur' }],
    'tenantId': [{ required: false, message: '租户ID', trigger: 'blur' }],
    'delState': [{ required: false, message: '有效状态[数据字典=del_state]', trigger: 'blur' }],
    'addUser': [{ required: false, message: '添加人', trigger: 'blur' }],
    'addUserId': [{ required: false, message: '添加人ID', trigger: 'blur' }],
    'addTime': [{ required: false, message: '添加时间', trigger: 'blur' }],
    'editUser': [{ required: false, message: '最近更新人', trigger: 'blur' }],
    'editUserId': [{ required: false, message: '最近更新人ID', trigger: 'blur' }],
    'lastEditTime': [{ required: false, message: '最近更新时间', trigger: 'blur' }],
    'serverNumber': [{ required: false, message: '服务器编号ID', trigger: 'blur' }],
  };
  const dicInner = {
    '___mes_bpm_condition_id': '主键ID',
    'mes_bpm_condition_id': 'mes_bpm_condition_id',
    '___mes_bpm_condition_bpmId': '',
    'mes_bpm_condition_bpmId': 'mes_bpm_condition_bpmId',
    '___mes_bpm_condition_lineId': '对应生产计划单id',
    'mes_bpm_condition_lineId': 'mes_bpm_condition_lineId',
    '___mes_bpm_condition_formId': '对应表单Id',
    'mes_bpm_condition_formId': 'mes_bpm_condition_formId',
    '___mes_bpm_condition_fieldName': '对应产品id',
    'mes_bpm_condition_fieldName': 'mes_bpm_condition_fieldName',
    '___mes_bpm_condition_fieldValue': '对应字段值',
    'mes_bpm_condition_fieldValue': 'mes_bpm_condition_fieldValue',
    '___mes_bpm_condition_fieldType': '对应字段类型 1文本  2单选框  3多选框  4下拉框 5、数字',
    'mes_bpm_condition_fieldType': 'mes_bpm_condition_fieldType',
    '___mes_bpm_condition_expression': '表达式',
    'mes_bpm_condition_expression': 'mes_bpm_condition_expression',
    '___mes_bpm_condition_orderNum': '预计用时(天)',
    'mes_bpm_condition_orderNum': 'mes_bpm_condition_orderNum',
    '___mes_bpm_condition_state': '状态 1 正常  5暂停 10废除',
    'mes_bpm_condition_state': 'mes_bpm_condition_state',
    '___mes_bpm_condition_remarks': '备注',
    'mes_bpm_condition_remarks': 'mes_bpm_condition_remarks',
    '___mes_bpm_condition_tenantType': '租户类型 1应用管理者2应用消息者',
    'mes_bpm_condition_tenantType': 'mes_bpm_condition_tenantType',
    '___mes_bpm_condition_tenantId': '租户ID',
    'mes_bpm_condition_tenantId': 'mes_bpm_condition_tenantId',
    '___mes_bpm_condition_delState': '有效状态[数据字典=del_state] 1有效  5删除',
    'mes_bpm_condition_delState': 'mes_bpm_condition_delState',
    '___mes_bpm_condition_addUser': '添加人',
    'mes_bpm_condition_addUser': 'mes_bpm_condition_addUser',
    '___mes_bpm_condition_addUserId': '添加人ID',
    'mes_bpm_condition_addUserId': 'mes_bpm_condition_addUserId',
    '___mes_bpm_condition_addTime': '添加时间',
    'mes_bpm_condition_addTime': 'mes_bpm_condition_addTime',
    '___mes_bpm_condition_editUser': '最近更新人',
    'mes_bpm_condition_editUser': 'mes_bpm_condition_editUser',
    '___mes_bpm_condition_editUserId': '最近更新人ID',
    'mes_bpm_condition_editUserId': 'mes_bpm_condition_editUserId',
    '___mes_bpm_condition_lastEditTime': '最近更新时间',
    'mes_bpm_condition_lastEditTime': 'mes_bpm_condition_lastEditTime',
    '___mes_bpm_condition_serverNumber': '服务器编号ID',
    'mes_bpm_condition_serverNumber': 'mes_bpm_condition_serverNumber',
  };
  import * as formApi from '@/apis/mesBpmForm.api.js';
  import * as mesBpmConditionExpressionApi from '@/apis/mesBpmConditionExpression.api.js';
  import { findOne } from '@/utils/lodash';
  
  export default {
    name: 'mesBpmConditionlist',
    data() {
      return {
        api: api,
        Rules,
        dicInner,
        formData: {
          'id': '',
          'lineId': '',
          'formId': '',
          'fieldName': '',
          'fieldValue': '',
          'fieldType': '',
          'expression': '',
          'orderNum': '',
          'state': '',
          'remarks': '',
          'tenantType': '',
          'tenantId': '',
          'delState': '',
          'addUser': '',
          'addUserId': '',
          'addTime': '',
          'editUser': '',
          'editUserId': '',
          'lastEditTime': '',
          'serverNumber': '',
          'bpmId': '',
        },
        lists: [],
        selectRows: [],
        classId: '',
        classIdPath: '',
        className: '',
        loading: false,
        isFold: false,
        tableRowClassName({ row, rowIndex }) {
          if (row.rowType == 'total') {
            return 'total-row';
          }
          return '';
        },
        formFieldList: [],
        mesBpmConditionExpressionList: [],
        findOne,
      };
    },
    components: {
      svgIcon: () => import('@codegenarate/svg-icon'),
      dicSelect: () => import('@/components/dicselect.vue'),
      dicTag: () => import('@/components/DicSelect/dic-tag.vue'),
    },
    computed: {},
    watch: {},
    methods: {
      /**
       * *  @params _data.bpmId
       * @params  _data.lineId
       *        * @desc 初始化        */
      async initByDialog(_data) {
        await this.getFormFieldsList(_data);
        fillData(this.formData, _data);
        console.log('初始化数据', this.formData);
        //初始化下拉
        this.changeFormId(this.formData.formId)
      },
      /**
       * @description: 修改 表单字段  联动 修改表达式下拉
       * @params
       * @return
       */
      changeFormId(valueid) {
        var one = findOne(this.formFieldList, item => item.id == valueid);
        this.formData.fieldName = one && one.fieldName;
        this.getBpmConmditionList({ fieldType: one && one.fieldType });
      },
      /**
       * @description:
       * @params _data.fieldType
       * @return
       */
      async getBpmConmditionList(_data) {
        if (_data && _data.fieldType) {
          var result = await mesBpmConditionExpressionApi.getList({
            fieldType: _data.fieldType,
            pageNum: 1,
            pageSize: 100,
            
          });
          this.mesBpmConditionExpressionList = result && result.data || [];
          console.log('表达式下拉是', this.mesBpmConditionExpressionList);
        } else {
          this.mesBpmConditionExpressionList = [];
        }
      },
      
      
      /**
       * @description:
       * @params data.bpmId
       * @return
       */
      async getFormFieldsList(_data) {
        var result = await formApi.getList({
          bpmId: _data.bpmId,
          pageNum: 1,
          pageSize: 100,
        });
        this.formFieldList = result && result.data || [];
        console.log('表单列表是', this.formFieldList);
      },
      
      async submitByDialog(_data) {
        var isyes = await validatePromise.call(this, 'queryForm');
        if (!isyes) {
          return { success: false, message: '请检查必填项' };
        }
        var func = this.formData.id ? api.update : api.add;
        var result = await func(this.formData);
        alertWithPaylod(result);
        return result;
      },
    },
  };</script>
